package com.hpsk.common;

/**
 * @author huangwang2832511019
 */
public class RespUtils {
    public static <T> RespResult<T> ok(T data) {
        return getBuild(RespCodeEnum.SUCCESS, data);
    }

    public static <T> RespResult<T> data(T data) {
        return getBuild(RespCodeEnum.SUCCESS, data);
    }

    public static <T> RespResult<T> ok() {
        return getBuild(RespCodeEnum.SUCCESS, null);
    }

    public static <T> RespResult<T> ok(String msg, T data) {
        return getBuild(RespCodeEnum.SUCCESS, msg, data);
    }

    public static <T> RespResult<T> err(Integer code, String msg) {
        return getBuild(code, msg);
    }

    public static <T> RespResult<T> err() {
        return getBuild(RespCodeEnum.SERVER_ERROR);
    }

    public static <T> RespResult<T> err(String msg) {
        return getBuild(RespCodeEnum.SERVER_ERROR, msg);
    }

    private static <T> RespResult<T> getBuild(RespCodeEnum respCodeEnum) {
        return getBuild(respCodeEnum, null);
    }

    private static <T> RespResult<T> getBuild(RespCodeEnum respCodeEnum, String msg) {
        return getBuild(respCodeEnum.getCode(), msg);
    }

    private static <T> RespResult<T> getBuild(RespCodeEnum respCodeEnum, String msg, T data) {
        return getBuild(respCodeEnum.getCode(), msg, data);
    }

    private static <T> RespResult<T> getBuild(RespCodeEnum respCodeEnum, T data) {
        return RespResult.<T>builder()
                .code(respCodeEnum.getCode())
                .msg(respCodeEnum.getMsg())
                .data(data)
                .build();
    }

    private static <T> RespResult<T> getBuild(Integer code, String msg) {
        return getBuild(code, msg, null);
    }

    private static <T> RespResult<T> getBuild(Integer code, String msg, T data) {
        return RespResult.<T>builder()
                .code(code)
                .msg(msg)
                .data(data)
                .build();
    }
}
